package com.heima.wemedia.controller.v1;

import com.heima.model.admin.dtos.ChannelDto;
import com.heima.model.common.dtos.PageResponseResult;
import com.heima.model.common.dtos.ResponseResult;
import com.heima.model.wemedia.pojos.WmChannel;
import com.heima.wemedia.mapper.WmChannelMapper;
import com.heima.wemedia.service.WmChannelService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @Description TODO
 * @Author bo.li
 * @Date 2023/3/16 10:49
 * @Version 1.0
 */
@RestController
//@RequestMapping("/api/v1/channel")
@Slf4j
public class WmChannelController {

    @Autowired
    private WmChannelService wmChannelService;
    @Autowired
    private WmChannelMapper wmChannelMapper;

    /**
     * 查询所有频道
     * @return
     */
    @GetMapping("/api/v1/channel/channels")
    public ResponseResult listAll(){
       return wmChannelService.findAll();
    }

    /**
     * 保存频道
     *
     * @param wmChannel
     * @return
     */
    @PostMapping("/api/v1/channel/saveChannel")
    public ResponseResult addChannel(@RequestBody WmChannel wmChannel){
        wmChannelService.save(wmChannel);
        return ResponseResult.okResult(true);
    }

    /**
     * 删除频道
     * @param id
     * @return
     */
    @GetMapping("/api/v1/channel/deleteChannel/{id}")
    public ResponseResult delChannel(@PathVariable Integer id){
        wmChannelService.removeById(id);
        return ResponseResult.okResult(true);
    }

    /**
     * 修改频道
     *
     * @param wmChannel
     * @return
     */
    @PostMapping("/api/v1/channel/updateChannel")
    public ResponseResult updChannel(@RequestBody WmChannel wmChannel){
        wmChannelService.updateById(wmChannel);
        return ResponseResult.okResult(true);
    }

    /**
     * 频道名称模糊分页查询
     * @param channelDto
     * @return
     */
    @PostMapping("/api/v1/channel/ChannelList")
    public PageResponseResult findChannelList(@RequestBody ChannelDto channelDto){
        log.info("频道分页查询：{}",channelDto);
        return wmChannelService.searchChannels(channelDto);
    }

    @PostMapping("/api/v1/channel/queryById/{id}")
    public WmChannel queryById(@PathVariable Integer id){
        log.info("用户id为：{}",id);
        return wmChannelMapper.selectById(id);
    }
}